import axios from 'axios';

export default {

    /**
    * @param url
    * @param method
    * @param data
    * @returns {Promise}
    */
    request(url, method, data) {
        return new Promise((resolve, reject) => {
            let Base64 = require('js-base64').Base64;
            axios({
                url: '/api'+url,//请求路径
                method: method,//请求模式
                data: data || {},//请求参数
                headers: { //sessionStorage.che_token
                    contentType: "application/json",
                    Authorization: "Bearer " +  JSON.parse(sessionStorage.getItem('token'))//Base64.decode(JSON.parse(sessionStorage.getItem('token'))) //token
                }
            }).then(res => {//成功回调
                resolve(res);
            }).catch(err => {//异常回调
                reject(err);
            })
        })
    },

}